package com.tinklabs.demo;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;

import butterknife.BindView;
import com.tinklabs.demo.activity.BaseActivity;
import com.tinklabs.demo.adapter.BaseViewPagerAdapter;
import com.tinklabs.demo.fragment.CityGuideFragment;

public class MainActivity extends BaseActivity {

    @BindView(R.id.activity_main_tabs)
    protected TabLayout tabLayout;

    @BindView(R.id.activity_main_viewPager)
    protected ViewPager viewPager;

    protected String[] tabs;

    protected ArrayList<Fragment> fragmentList;

    @Override
    protected int getLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initData() {
        initTabData();
        initFragmentData();
    }

    private void initTabData() {
        tabs = new String[]{"CITY GUIDE","SHOP","EAT"};
    }

    private void initFragmentData() {
        fragmentList = new ArrayList<>();
        fragmentList.add(new CityGuideFragment());
        fragmentList.add(new CityGuideFragment());
        fragmentList.add(new CityGuideFragment());
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        initViewPager();
        initTab();
    }

    private void initViewPager() {
        viewPager.setOffscreenPageLimit(fragmentList.size() - 1);
        BaseViewPagerAdapter adapter = new BaseViewPagerAdapter(getSupportFragmentManager(), tabs, fragmentList);
        viewPager.setAdapter(adapter);

        tabLayout.setupWithViewPager(viewPager);
    }

    private void initTab() {
        tabLayout.setTabTextColors(Color.parseColor("#999999"), Color.parseColor("#303F9F"));
    }
}
